package com.shuoyue.ycgk.ui.course.info;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.entity.CourseData;
import com.shuoyue.ycgk.entity.course_teacher.Teacher;
import com.shuoyue.ycgk.ui.course.adapter.CourseDataAdapter;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.ArrayList;

import butterknife.BindView;

public class FragmentCourseData extends BaseCourseInfoFragment {

    @BindView(R.id.list)
    RecyclerView list;
    ArrayList<CourseData> courseDatas;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;

    public static FragmentCourseData newInstance(ArrayList<Teacher> courseDatas) {
        FragmentCourseData fragment = new FragmentCourseData();
        Bundle args = new Bundle();
        args.putSerializable("data", courseDatas);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void initParams(Bundle bundle) {
        courseDatas = (ArrayList<CourseData>) bundle.getSerializable("data");

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_course_data;
    }

    @Override
    protected void initView() {
        list.setLayoutManager(new LinearLayoutManager(mContext));
        list.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 8)));
        scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            if (scrollY <= 0) {
                isScrollAtTop = true;
            } else {
                isScrollAtTop = false;
            }
        });
    }

    @Override
    protected void initData() {
        setCourseData(courseDatas);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }


    void setCourseData(ArrayList<CourseData> teacher) {
        CourseDataAdapter teacherAdapter = new CourseDataAdapter(teacher);
        list.setAdapter(teacherAdapter);
    }

    @Override
    public String getTitle() {
        return "授课老师";
    }
}
